#include "procedure.h"
#include "iostream"
#include <unistd.h>
#include "can_uim.h"
#include "rs485.h"
#include <sys/ipc.h>
#include <sys/msg.h>
#include "config.h"
#include "common.h"
#include "sharemem.h"

#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>

ob_manage * g_ptrObManage = NULL;

sem_t sem_liquid_detect;

using namespace std;

CProcedure::CProcedure()
{
    m_eleId = 0;
    m_max_proc_num = 0;
    m_curr_proc_num = 0;
    m_exitFlag = 0;
    procNodeArrHead = NULL;
    m_moduleId = -1; 
    m_ptrParamIn = NULL;

    m_deleteFlag = 0;   
}

CProcedure::~CProcedure()
{

    for(int i=0;i<m_max_proc_num;i++)
    {
        if(this->procNodeArrHead[i].dataDesired)
        {
            delete [] this->procNodeArrHead[i].dataDesired;
            this->procNodeArrHead[i].dataDesired = NULL;
        }

    }   
    
    m_eleId = 0;
    m_max_proc_num = 0;
    m_curr_proc_num = 0;
    m_exitFlag = 0;
    m_moduleId = -1;
    
    if(procNodeArrHead)
    {
        delete [] procNodeArrHead;
        procNodeArrHead = NULL;
    }

    if(m_ptrParamIn)
    {
        switch(m_paramInType)
        {
            case PARAM_FOR_BASHZ:
            {
                move_param * ptrCtl = (move_param*)m_ptrParamIn;
                delete ptrCtl;
            }
            break;
            case PARAM_FOR_DJCLEAN:
            {
                djcleanParamCtl * ptrCtl = (djcleanParamCtl *)m_ptrParamIn;
                delete [] ptrCtl;
            }
            break;
            case PARAM_FOR_TRANSTUBE:
            {
                tube_trans * ptrCtl = (tube_trans *)m_ptrParamIn;
                delete ptrCtl;
            }
            break;
            default:
            break;
        }

        m_ptrParamIn = NULL;
    }
    

    printf("~CProcedure\n");
    
}

void CProcedure::exit(void)
{
    for(int i=0;i<m_max_proc_num;i++)
    {
        if(this->procNodeArrHead[i].dataDesired)
        {
            delete [] this->procNodeArrHead[i].dataDesired;
            this->procNodeArrHead[i].dataDesired = NULL;
        }

    }

    if(procNodeArrHead)
    {
        delete [] procNodeArrHead;
        procNodeArrHead = NULL;
    }

    m_exitFlag = 1;
    m_curr_proc_num = 0;
}

void printCheckDataStatus(eleActCheck * data)
{
    eleActCheck * ptrCheckData = data;
    while(NULL!=ptrCheckData)
    {
        printf("sid[%d],status[%d]\n",ptrCheckData->valueDesired.sid,ptrCheckData->status);
        ptrCheckData = ptrCheckData->next;
    }
}

void CProcedure::start(int moduleId = -1)
{
    m_exitFlag = 0;
    void * res;
    //while(!exitFlag)
    //{

    //}

    this->setModuleId(moduleId);
    if(I_MODULE_DJLIQUID==moduleId)
    {
        pthread_create(&procThreadHandle,NULL,procThread_dynamicRead,this);
    }
    else
    {
        pthread_create(&procThreadHandle,NULL,procThread,this);
    }
    

    //pthread_join(procThreadHandle,&res);    
}

void CProcedure::setModuleId(int idIn)
{
    m_moduleId = idIn;
}

int CProcedure::getModuleId(void)
{
    return m_moduleId;
}

int CProcedure::setParamIn(int paramType,void * paramIn)
{
    m_paramInType = paramType;
    m_ptrParamIn = paramIn;
}

void * CProcedure::getParamIn(void)
{
    return m_ptrParamIn;
}


int CProcedure::read_param(void * dataOut)
{
    switch (m_paramInType)
    {
        case PARAM_FOR_DJCLEAN:
        {
            djcleanParamCtl * ptrCtl = (djcleanParamCtl *)m_ptrParamIn;
            ptrCtl+=m_curr_proc_num;
            djclean_read_param(dataOut,ptrCtl);
        }
        break;
        default:
        break;
    }
}

void *procThread(void * paramIn)
{
    CProcedure * ptrProc = (CProcedure *)paramIn;
    
    //pthread_detach(pthread_self());


    char * memBuff = new char[MAX_PARAM_BUFF_LEN];

    int countTime = 0;
    int queryTimes = 0;
    int tempInterval = 0;

    int * ptrNum = (int *)memBuff;
    paramEleCtl * ptrParam = NULL;   

    while(!ptrProc->getExitFlag())
    {
        int curNodeNum = ptrProc->getCurrProcNum();
        int curStatus = ptrProc->procNodeArrHead[curNodeNum].stage;
        switch(curStatus)
        {
            case STAGE_NOT_START:
            {
                if(ptrProc->procNodeArrHead[curNodeNum].readParamFunc)
                {
                    memset(memBuff,0,MAX_PARAM_BUFF_LEN);
                    ptrProc->procNodeArrHead[curNodeNum].readParamFunc(memBuff,ptrProc->getParamIn());
                    
                    ptrParam = (paramEleCtl *)(ptrNum+1);
                    int num = (*ptrNum > MAX_OB_NUM)?MAX_OB_NUM:*ptrNum;
                    if(num==0)
                    {
                       ptrProc->procNodeArrHead[curNodeNum].stage = STAGE_END;
                       continue; 
                    }
                    for(int i=0;i<num;i++)
                    {
                       int eleId = convertEleCtlId(ptrParam->sid);
                       g_ptrObManage->attach(ptrProc,eleId);
                       ptrParam++;
                    }

                    set_check_data(memBuff,(void**)(&ptrProc->procNodeArrHead[curNodeNum].dataDesired));
                    
                    if(ptrProc->procNodeArrHead[curNodeNum].actFunc)
                    {
                        int actRet = ptrProc->procNodeArrHead[curNodeNum].actFunc(memBuff);
                        if(actRet == -1)
                        {
                           ptrProc->procNodeArrHead[curNodeNum].stage = STAGE_END;
                           curNodeNum = ptrProc->getMaxProcNum() - 1;
                           ptrProc->setCurrProcNum(ptrProc->getMaxProcNum() - 1);
                           
                           ptrProc->procNodeArrHead[curNodeNum].stage = STAGE_END;
                           printf("exception occurred, exit entire module procedure\n");
                           //exit entire procedure;
                        }
                        else if(actRet==1)
                        {
                            ptrProc->procNodeArrHead[curNodeNum].stage = STAGE_END;
                        }
                        else
                        {
                            //normal executing
                            ptrProc->procNodeArrHead[curNodeNum].stage = STAGE_RUNNING;
                            printf("change state from not_start to running 111,curNodeNum:%d\n",curNodeNum);
                        }
                        
                    }
                    else
                    {
                        /* code */
                        ptrProc->procNodeArrHead[curNodeNum].stage = STAGE_END;
                    }
                }
                else
                {
                    /* code */
                    * ptrNum = 0;
                    ptrProc->procNodeArrHead[curNodeNum].stage = STAGE_END;
                }                              
                
            }
            break;

            case STAGE_RUNNING:
            {
                if(countTime > ptrProc->procNodeArrHead[curNodeNum].runtime)
                {
                    printf("change state from running to query 111\n");

                    printCheckDataStatus(ptrProc->procNodeArrHead[curNodeNum].dataDesired);
                    ptrProc->procNodeArrHead[curNodeNum].stage = STAGE_QUERY;
                }
                else if(isAllAckFinished(ptrProc->procNodeArrHead[curNodeNum].dataDesired))
                {
                    ptrProc->procNodeArrHead[curNodeNum].stage = STAGE_END;
                }
            }
            break;
            case STAGE_QUERY:
            {
                if(tempInterval >= ptrProc->procNodeArrHead[curNodeNum].queryInterval)
                {
                    if(ptrProc->procNodeArrHead[curNodeNum].queryFunc)
                    {
                        printf("send for querying\n");
                        ptrProc->procNodeArrHead[curNodeNum].queryFunc(memBuff);
                    }
                    queryTimes++;
                    tempInterval = 0;

                    if(queryTimes>ptrProc->procNodeArrHead[curNodeNum].queryTimes)
                    {
                        ptrProc->procNodeArrHead[curNodeNum].stage = STAGE_END;
                    }
                }
                
            }
            break;
            case STAGE_END:
            {
                ptrParam = (paramEleCtl *)(ptrNum+1);
                int num = (*ptrNum > MAX_OB_NUM)?MAX_OB_NUM:*ptrNum;
                for(int i=0;i<num;i++)
                {
                    //num of electl for one step action
                    int eleId = convertEleCtlId(ptrParam->sid);
                    g_ptrObManage->dettach(ptrProc,eleId);
                    ptrParam++;
                }
                
                curNodeNum ++ ;
                countTime = 0;
                tempInterval = 0;
                queryTimes = 0;
                printf("num:%d,curNodeNum:%d,maxnum:%d\n",num,curNodeNum,ptrProc->getMaxProcNum());
                if(curNodeNum>=ptrProc->getMaxProcNum())
                {
                    //printf("detele memBuff\n");
                    delete [] memBuff;
                    //printf("set exit flag to 1\n");
                    ptrProc->setExitFlag(1);
                }
                else
                {
                    
                    ptrProc->setCurrProcNum(curNodeNum);
                }
                
            }
            break;
            default:
            break;
        }
        usleep(20000);
        countTime += 20000;

        if(STAGE_QUERY == curStatus)
        {
            tempInterval += 20000;
        }       
         
    }
    //printf("exit procedure Thread 111\n");
    msgQueueAck stMsgQueueAck;
    memset(&stMsgQueueAck,0,sizeof(msgQueueAck));
    stMsgQueueAck.type = QUEUE_MSG_TYPE_GRPC;
    stMsgQueueAck.msg.statusCode = 0;
    stMsgQueueAck.msg.moduleId = ptrProc->getModuleId();
    stMsgQueueAck.msg.sid = 0xa5;
    if(msgsnd(g_msg_id, (void*)&stMsgQueueAck, sizeof(msgAck), 0) < 0)
    {
        printf("send ack failed\n");
    }

    //ptrProc->exit();
    pthread_detach(pthread_self());
    ptrProc->setDelFlag(1);    
    printf("exit procedure Thread\n");    
}

void *procThread_dynamicRead(void * paramIn)
{
    CProcedure * ptrProc = (CProcedure *)paramIn;
    
    pthread_detach(pthread_self());


    char * memBuff = new char[MAX_PARAM_BUFF_LEN];

    int countTime = 0;
    int queryTimes = 0;
    int tempInterval = 0;

    int * ptrNum = (int *)memBuff;
    paramEleCtl * ptrParam = NULL;   

    while(!ptrProc->getExitFlag())
    {
        int curNodeNum = ptrProc->getCurrProcNum();
        int curStatus = ptrProc->procNodeArrHead[curNodeNum].stage;
        switch(curStatus)
        {
            case STAGE_NOT_START:
            {
                
                memset(memBuff,0,MAX_PARAM_BUFF_LEN);
                //ptrProc->procNodeArrHead[curNodeNum].readParamFunc(memBuff,ptrProc->getParamIn());
                ptrProc->read_param(memBuff);
                ptrParam = (paramEleCtl *)(ptrNum+1);
                int num = (*ptrNum > MAX_OB_NUM)?MAX_OB_NUM:*ptrNum;
                if(num==0)
                {
                    ptrProc->procNodeArrHead[curNodeNum].stage = STAGE_END;
                    continue; 
                }
                for(int i=0;i<num;i++)
                {
                    int eleId = convertEleCtlId(ptrParam->sid);
                    g_ptrObManage->attach(ptrProc,eleId);
                    ptrParam++;
                }

                set_check_data(memBuff,(void**)(&ptrProc->procNodeArrHead[curNodeNum].dataDesired));
                
                if(ptrProc->procNodeArrHead[curNodeNum].actFunc)
                {
                    int actRet = ptrProc->procNodeArrHead[curNodeNum].actFunc(memBuff);
                    if(actRet == -1)
                    {
                        ptrProc->procNodeArrHead[curNodeNum].stage = STAGE_END;
                        curNodeNum = ptrProc->getMaxProcNum() - 1;
                        ptrProc->setCurrProcNum(ptrProc->getMaxProcNum() - 1);
                        
                        ptrProc->procNodeArrHead[curNodeNum].stage = STAGE_END;
                        printf("exception occurred, exit entire module procedure\n");
                        //exit entire procedure;
                    }
                    else if(actRet==1)
                    {
                        ptrProc->procNodeArrHead[curNodeNum].stage = STAGE_END;
                    }
                    else
                    {
                        //normal executing
                        ptrProc->procNodeArrHead[curNodeNum].stage = STAGE_RUNNING;
                        printf("change state from not_start to running 111,curNodeNum:%d\n",curNodeNum);
                    }
                    
                }
                else
                {
                    /* code */
                    ptrProc->procNodeArrHead[curNodeNum].stage = STAGE_END;
                }
                                              
                
            }
            break;

            case STAGE_RUNNING:
            {
                if(countTime > ptrProc->procNodeArrHead[curNodeNum].runtime)
                {
                    printf("change state from running to query 111\n");

                    printCheckDataStatus(ptrProc->procNodeArrHead[curNodeNum].dataDesired);
                    ptrProc->procNodeArrHead[curNodeNum].stage = STAGE_QUERY;
                }
                else if(isAllAckFinished(ptrProc->procNodeArrHead[curNodeNum].dataDesired))
                {
                    ptrProc->procNodeArrHead[curNodeNum].stage = STAGE_END;
                }
            }
            break;
            case STAGE_QUERY:
            {
                if(tempInterval >= ptrProc->procNodeArrHead[curNodeNum].queryInterval)
                {
                    if(ptrProc->procNodeArrHead[curNodeNum].queryFunc)
                    {
                        printf("send for querying\n");
                        ptrProc->procNodeArrHead[curNodeNum].queryFunc(memBuff);
                    }
                    queryTimes++;
                    tempInterval = 0;

                    if(queryTimes>ptrProc->procNodeArrHead[curNodeNum].queryTimes)
                    {
                        ptrProc->procNodeArrHead[curNodeNum].stage = STAGE_END;
                    }
                }
                
            }
            break;
            case STAGE_END:
            {
                ptrParam = (paramEleCtl *)(ptrNum+1);
                int num = (*ptrNum > MAX_OB_NUM)?MAX_OB_NUM:*ptrNum;
                for(int i=0;i<num;i++)
                {
                    //num of electl for one step action
                    int eleId = convertEleCtlId(ptrParam->sid);
                    g_ptrObManage->dettach(ptrProc,eleId);
                    ptrParam++;
                }
                
                curNodeNum ++ ;
                countTime = 0;
                tempInterval = 0;
                queryTimes = 0;
                printf("num:%d,curNodeNum:%d,maxnum:%d\n",num,curNodeNum,ptrProc->getMaxProcNum());
                if(curNodeNum>=ptrProc->getMaxProcNum())
                {
                    //printf("detele memBuff\n");
                    delete [] memBuff;
                    //printf("set exit flag to 1\n");
                    ptrProc->setExitFlag(1);
                }
                else
                {
                    
                    ptrProc->setCurrProcNum(curNodeNum);
                }
                
            }
            break;
            default:
            break;
        }
        usleep(20000);
        countTime += 20000;

        if(STAGE_QUERY == curStatus)
        {
            tempInterval += 20000;
        }       
         
    }
    //printf("exit procedure Thread 111\n");
    msgQueueAck stMsgQueueAck;
    memset(&stMsgQueueAck,0,sizeof(msgQueueAck));
    stMsgQueueAck.type = QUEUE_MSG_TYPE_GRPC;
    stMsgQueueAck.msg.statusCode = 0;
    stMsgQueueAck.msg.moduleId = ptrProc->getModuleId();
    stMsgQueueAck.msg.sid = 0xa5;
    if(msgsnd(g_msg_id, (void*)&stMsgQueueAck, sizeof(msgAck), 0) < 0)
    {
        printf("send ack failed\n");
    }

    //ptrProc->exit();
    
    ptrProc->setDelFlag(1);    
    printf("exit procedure Thread\n");    
}

void *procThread_dj(void * paramIn)
{
    CProcedure_Dj * ptrProc = (CProcedure_Dj *)paramIn;
    char * memBuff = new char[MAX_PARAM_BUFF_LEN];

    int countTime = 0;
    int queryTimes = 0;
    int tempInterval = 0;

    int * ptrNum = (int *)memBuff;
    paramEleCtl * ptrParam = NULL;

    int indexPos = 0;

    printf("start procThread_dj\n");
    for(indexPos=0;indexPos<ptrProc->getNumPos();indexPos++) 
    {
        printf("the %dth pos\n",indexPos);

      
    ptrProc->setExitFlag(0);
    ptrProc->setCurrProcNum(0);
    
    for(int iNode = 0;iNode<ptrProc->getMaxProcNum();iNode++)
    {
        ptrProc->procNodeArrHead[iNode].stage = STAGE_NOT_START;
    }   

    while(!ptrProc->getExitFlag())
    {
        int curNodeNum = ptrProc->getCurrProcNum();
        int curStatus = ptrProc->procNodeArrHead[curNodeNum].stage;
        switch(curStatus)
        {
            case STAGE_NOT_START:
            {
                
                memset(memBuff,0,MAX_PARAM_BUFF_LEN);
                //ptrProc->procNodeArrHead[curNodeNum].readParamFunc(memBuff,ptrProc->getParamIn());
                ptrProc->getProcParam(indexPos,curNodeNum,memBuff);

                ptrParam = (paramEleCtl *)(ptrNum+1);
                int num = (*ptrNum > MAX_OB_NUM)?MAX_OB_NUM:*ptrNum;
                if(num==0)
                {
                    ptrProc->procNodeArrHead[curNodeNum].stage = STAGE_END;
                    continue; 
                }
                for(int i=0;i<num;i++)
                {
                    int eleId = convertEleCtlId(ptrParam->sid);
                    g_ptrObManage->attach(ptrProc,eleId);
                    ptrParam++;
                }

                set_check_data(memBuff,(void**)(&ptrProc->procNodeArrHead[curNodeNum].dataDesired));
                
                if(ptrProc->procNodeArrHead[curNodeNum].actFunc)
                {
                    int actRet = ptrProc->procNodeArrHead[curNodeNum].actFunc(memBuff);
                    if(actRet == -1)
                    {
                        ptrProc->procNodeArrHead[curNodeNum].stage = STAGE_END;
                        curNodeNum = ptrProc->getMaxProcNum() - 1;
                        ptrProc->setCurrProcNum(ptrProc->getMaxProcNum() - 1);
                        
                        ptrProc->procNodeArrHead[curNodeNum].stage = STAGE_END;
                        printf("exception occurred, exit entire module procedure\n");
                        //exit entire procedure;
                    }
                    else if(actRet==1)
                    {
                        ptrProc->procNodeArrHead[curNodeNum].stage = STAGE_END;
                    }
                    else
                    {
                        //normal executing
                        ptrProc->procNodeArrHead[curNodeNum].stage = STAGE_RUNNING;
                        printf("change state from not_start to running 111,curNodeNum:%d\n",curNodeNum);
                    }
                    
                }
                else
                {
                    /* code */
                    ptrProc->procNodeArrHead[curNodeNum].stage = STAGE_END;
                }
                                              
                
            }
            break;

            case STAGE_RUNNING:
            {
                if(countTime > ptrProc->procNodeArrHead[curNodeNum].runtime)
                {
                    printf("change state from running to query 111\n");

                    printCheckDataStatus(ptrProc->procNodeArrHead[curNodeNum].dataDesired);
                    ptrProc->procNodeArrHead[curNodeNum].stage = STAGE_QUERY;
                }
                else if(isAllAckFinished(ptrProc->procNodeArrHead[curNodeNum].dataDesired))
                {
                    ptrProc->procNodeArrHead[curNodeNum].stage = STAGE_END;
                }
            }
            break;
            case STAGE_QUERY:
            {
                if(tempInterval >= ptrProc->procNodeArrHead[curNodeNum].queryInterval)
                {
                    if(ptrProc->procNodeArrHead[curNodeNum].queryFunc)
                    {
                        printf("send for querying\n");
                        ptrProc->procNodeArrHead[curNodeNum].queryFunc(memBuff);
                    }
                    queryTimes++;
                    tempInterval = 0;

                    if(queryTimes>ptrProc->procNodeArrHead[curNodeNum].queryTimes)
                    {
                        ptrProc->procNodeArrHead[curNodeNum].stage = STAGE_END;
                    }
                }
                
            }
            break;
            case STAGE_END:
            {
                ptrParam = (paramEleCtl *)(ptrNum+1);
                int num = (*ptrNum > MAX_OB_NUM)?MAX_OB_NUM:*ptrNum;
                for(int i=0;i<num;i++)
                {
                    //num of electl for one step action
                    int eleId = convertEleCtlId(ptrParam->sid);
                    g_ptrObManage->dettach(ptrProc,eleId);
                    ptrParam++;
                }
                
                curNodeNum ++ ;
                countTime = 0;
                tempInterval = 0;
                queryTimes = 0;
                printf("num:%d,curNodeNum:%d,maxnum:%d\n",num,curNodeNum,ptrProc->getMaxProcNum());
                if(curNodeNum>=ptrProc->getMaxProcNum())
                {
                    //printf("detele memBuff\n");
                    //delete [] memBuff;
                    //printf("set exit flag to 1\n");
                    ptrProc->setExitFlag(1);
                    //ptrProc->exit();
                }
                else
                {
                    
                    ptrProc->setCurrProcNum(curNodeNum);
                }
                
            }
            break;
            default:
            break;
        }
        usleep(20000);
        countTime += 20000;

        if(STAGE_QUERY == curStatus)
        {
            tempInterval += 20000;
        }       
         
    }

    }
    //printf("exit procedure Thread 111\n");
    msgQueueAck stMsgQueueAck;
    memset(&stMsgQueueAck,0,sizeof(msgQueueAck));
    stMsgQueueAck.type = QUEUE_MSG_TYPE_GRPC;
    stMsgQueueAck.msg.statusCode = 0;
    stMsgQueueAck.msg.moduleId = ptrProc->getModuleId();
    stMsgQueueAck.msg.sid = 0xa5;
    if(msgsnd(g_msg_id, (void*)&stMsgQueueAck, sizeof(msgAck), 0) < 0)
    {
        printf("send ack failed\n");
    }

    //ptrProc->exit();
    //pthread_detach(pthread_self());
    delete [] memBuff;
    ptrProc->setDelFlag(1);    
    printf("exit procedure Thread\n");    

}

int CProcedure_Dj::getNumPos(void)
{
    return m_numHole;
}

int CProcedure_Dj::getNextPos(pos_dj* djPosOut)
{
    printf("enter in getNextPos\n");

    if(m_currPosNum == 0)
    { 
        printf("cnt in list:%d\n",m_listPos.size());      
       m_currIt = m_listPos.begin();
    }
    else if(m_currIt!=m_listPos.end())
    {        
        m_currIt++;
    }
    
    
    djPosOut->x = m_currIt->x;
    djPosOut->y = m_currIt->y;
    djPosOut->z = m_currIt->z;
    djPosOut->pump = m_currIt->pump;

    m_currPosNum ++;       

    return 0;
    
}

void CProcedure_Dj::setCurrPosIndex(int posIndexIn)
{
    m_currPosNum = posIndexIn;
}


int CProcedure_Dj::getProcParam(int indexPos,int indexProc, void * paramOut)
{
    char readPath[256] = {0};
    memset(readPath,0,256); 

    const int sid_djx = 49;
    const int sid_djy = 50;

    const int sid_djz = 51;

    const int sid_pump = 40;
    
    if(getMaxProcNum()==4)
    {
        sprintf(readPath,"%s%d%s","dj.step",indexProc+1,".electl");
    }
    else if(getMaxProcNum()==2)
    {
        sprintf(readPath,"%s%d%s","dj.step",(indexProc+1)*2,".electl");
    }
    else if(getMaxProcNum()==3)
    {
        sprintf(readPath,"%s%d%s","dj.step",indexProc+2,".electl");
    }
    
    
    printf("enter getProcParam, path of json:%s\n",readPath);

    int retRead = read_param_json(I_FILE_DJ,readPath,paramOut,NULL);

    printf("read jason ret=%d\n",retRead);
    
    pos_dj posToSet;
    memset(&posToSet,0,sizeof(pos_dj));
    
    if(indexProc==0)
    {
       getNextPos(&posToSet);
    }
    else
    {
       if(m_currIt!=m_listPos.end())
       {
           posToSet.x = m_currIt->x;
           posToSet.y = m_currIt->y;
           posToSet.pump = m_currIt->pump;
           posToSet.z = m_currIt->z;
       }
       else
       {
           posToSet.x = 0;
           posToSet.y = 0;
           posToSet.pump = 0;
           posToSet.z = 0;
       }
       
       
    }
    
    
    
    
    
    int * ptrNum = (int*)paramOut;
    paramEleCtl * ptrParamEleCtl = (paramEleCtl *) (ptrNum+1);
    
    //printf("num electl:%d\n",* ptrNum);
    if(getMaxProcNum()==4)
    {
        if(indexProc==1)
        {
            
            for(int i=0;i<(*ptrNum);i++)
            {
                if(ptrParamEleCtl[i].sid == sid_djx)//dj x
                {
                    ptrParamEleCtl[i].position = posToSet.x; 
                }
                else if(ptrParamEleCtl[i].sid == sid_djy) //dj y
                {
                    ptrParamEleCtl[i].position = posToSet.y; 
                }
            }
            printf("set (x,y)(%d,%d)\n",posToSet.x,posToSet.y);
        }
        else if(indexProc==2)
        {
            for(int i=0;i<(*ptrNum);i++)
            {
                if(ptrParamEleCtl[i].sid == sid_djz)//dj x
                {
                    ptrParamEleCtl[i].position = posToSet.z; 
                }
            }
            printf("set z:%d\n",posToSet.z);
        }
        else if(indexProc==3)
        {
            for(int i=0;i<(*ptrNum);i++)
            {
                if(ptrParamEleCtl[i].sid == sid_pump)//dj x
                {
                    ptrParamEleCtl[i].position = posToSet.pump*64; 
                }
            }
            printf("set pump:%d\n",posToSet.pump);
        }

    }
    else if(getMaxProcNum()==2)
    {
        if(indexProc==0)
        {
            
            for(int i=0;i<(*ptrNum);i++)
            {
                if(ptrParamEleCtl[i].sid == sid_djx)//dj x
                {
                    ptrParamEleCtl[i].position = posToSet.x; 
                }
                else if(ptrParamEleCtl[i].sid == sid_djy) //dj y
                {
                    ptrParamEleCtl[i].position = posToSet.y; 
                }
                else if(ptrParamEleCtl[i].sid == sid_djz) //dj z
                {
                    ptrParamEleCtl[i].position = m_refPos.z; 
                }
            }
            printf("set (x,y,z)(%d,%d,%d)\n",posToSet.x,posToSet.y,posToSet.z);
        }        
        else if(indexProc==1)
        {
            for(int i=0;i<(*ptrNum);i++)
            {
                if(ptrParamEleCtl[i].sid == sid_pump)//dj x
                {
                    ptrParamEleCtl[i].position = posToSet.pump*64; 
                }
            }
            printf("set pump:%d\n",posToSet.pump);
        }

    }
    else if(getMaxProcNum()==3)
    {
        if(indexProc==0)
        {
            
            for(int i=0;i<(*ptrNum);i++)
            {
                if(ptrParamEleCtl[i].sid == sid_djx)//dj x
                {
                    ptrParamEleCtl[i].position = posToSet.x; 
                }
                else if(ptrParamEleCtl[i].sid == sid_djy) //dj y
                {
                    ptrParamEleCtl[i].position = posToSet.y; 
                }
                // else if(ptrParamEleCtl[i].sid == sid_djz) //dj z
                // {
                //     ptrParamEleCtl[i].position = m_refPos.z; 
                // }
            }
            printf("set (x,y)(%d,%d)\n",posToSet.x,posToSet.y);
        }        
        else if(indexProc==2)
        {
            for(int i=0;i<(*ptrNum);i++)
            {
                if(ptrParamEleCtl[i].sid == sid_pump)//dj x
                {
                    ptrParamEleCtl[i].position = posToSet.pump*64; 
                }
            }
            printf("set pump:%d\n",posToSet.pump);
        }

    }
    
}

int getOneTraceNode(pos_dj* refPos, char * strBuff, pos_dj* posOut, int deltaXIn, int deltaYIn)
{
    if(strlen(strBuff)<=1)
    {
        return 4;
    }
    if(strBuff[0]>='A' && strBuff[0]<='F')
    {
        posOut->x = refPos->x + (strBuff[0] - 'A')*deltaXIn;
    }
    else
    {
        printf("[%c] is not valid,%s\n",strBuff[0], strBuff);
        return 1;
        
    }

    if(strBuff[1]>='a' && strBuff[1]<='h')
    {
        posOut->y = refPos->y + (strBuff[1] - 'a')*deltaYIn;
    }
    else
    {
        printf("[%c] is not valid,%s\n",strBuff[1], strBuff);
        return 2;
    } 

    posOut->z = refPos->z; 

    errno = 0;

    int tmpPump =  strtol(strBuff+2, NULL, 10);


    

    if( (errno != 0 && tmpPump == 0))
    {
        printf("[%s] is not valid,%s\n",strBuff+2, strBuff);
        return 3;
    }
    else
    {
        posOut->pump = tmpPump;
    }

    return 0;
}


int CProcedure_Dj::setMoveTrace(char * buffIn, int len,void * actParamIn)
{
    char * ptrBuff = buffIn;

    char * ret = strchr(ptrBuff,',');

    char buffOnePos[64];
    
    dj_actParam * ptrParam = (dj_actParam *)actParamIn;
    

    m_listPos.clear();
    m_numHole = 0;
    m_currPosNum = 0;

    m_refPos.x = ptrParam->refPos.x;
    m_refPos.y = ptrParam->refPos.y;
    m_refPos.z = ptrParam->refPos.z;

    m_deltaX = ptrParam->deltaX;
    m_deltaY = ptrParam->deltaY;

    pos_dj djPosTmp;

    int tmpPump = 0;
    
    int getRet = 0;

    while(ret)
    {
        memset(buffOnePos,0,64);
        memcpy(buffOnePos,ptrBuff,ret-ptrBuff);
        ptrBuff = ret;
        ptrBuff ++ ;
        ret = strchr(ptrBuff,',');        
        
        getRet = getOneTraceNode(&(ptrParam->refPos),buffOnePos,&djPosTmp,m_deltaX,m_deltaY);
        if(getRet==0)
        {
            m_numHole ++;

            m_listPos.push_back(djPosTmp);
        }        
        
    }

    getRet = getOneTraceNode(&(ptrParam->refPos),ptrBuff,&djPosTmp,m_deltaX,m_deltaY);
    if(getRet==0)
    {
        m_numHole ++;
        m_listPos.push_back(djPosTmp);
    }

    std::list<pos_dj>::iterator itDjPos = m_listPos.begin();

    while(itDjPos!=m_listPos.end())
    {
       printf("x:%d,y:%d,pump:%d\n",
       itDjPos->x,
       itDjPos->y,
       itDjPos->pump);
       itDjPos++; 
    }

}

int CProcedure_Dj::setDelta(int deltaX, int deltaY)
{
    m_deltaX = deltaX;
    m_deltaY = deltaY;
}

int CProcedure_Dj::start_dj(int moduleId)
{
    this->setExitFlag(0);
    void * res;
    //while(!exitFlag)
    //{

    //}

    this->setModuleId(moduleId);
    pthread_create(&procThreadHandle,NULL,procThread_dj,this);

    pthread_join(procThreadHandle,&res);
}

CProcedure_Dj::CProcedure_Dj()
{
    m_numHole = 0;    
    m_listPos.clear(); 
    m_currPosNum = 0;
    
    memset(&m_refPos,0,sizeof(pos_dj));//position of A1
    m_deltaX = 0;
    m_deltaY = 0;
}

CProcedure_Dj::~CProcedure_Dj()
{
    m_listPos.clear();

    memset(&m_refPos,0,sizeof(pos_dj));//position of A1
    m_deltaX = 0;
    m_deltaY = 0;
    setExitFlag(1);
    setDelFlag(1);
}

void CProcedure::setCurrProcNum(int numIn)
{
    m_curr_proc_num = numIn;
}


int CProcedure::getExitFlag(void)
{
    return m_exitFlag;
}

int CProcedure::getCurrProcNum(void)
{
    return m_curr_proc_num;
}

void CProcedure::configProc(procNode * ptrProcNodeHead,int numProcNode)
{
    procNodeArrHead = ptrProcNodeHead;
    m_max_proc_num = numProcNode;
    m_curr_proc_num = 0;
}

void CProcedure::setExitFlag(int flagIn)
{
    m_exitFlag = flagIn;
}


int CProcedure::getDelFlag(void)
{
    return m_deleteFlag;
}


void CProcedure::setDelFlag(int flagIn)
{
    m_deleteFlag = flagIn;
}


int CProcedure::getMaxProcNum(void)
{
    return m_max_proc_num;
}

void CProcedure::updateOneProc(void * dataIn)
{
    if(procNodeArrHead[this->getCurrProcNum()].updateFunc)
    {
        int ret = procNodeArrHead[m_curr_proc_num].updateFunc(dataIn,procNodeArrHead[this->getCurrProcNum()].dataDesired);
        if(ret)
        {
              //printf("updateOneProc stage is %d,currProcNum:%d,getCurrProcNum:%d\n",
              //procNodeArrHead[m_curr_proc_num].stage,
              //m_curr_proc_num,
              //this->getCurrProcNum());
             
             if(procNodeArrHead[m_curr_proc_num].stage == STAGE_RUNNING
                || procNodeArrHead[m_curr_proc_num].stage == STAGE_QUERY)
             {
                 //printf(" change status to stage end\n");
                 procNodeArrHead[m_curr_proc_num].stage = STAGE_END;
             }
        }
    }
}

void ob_manage::attach(CProcedure * ptrIn,int obId)
{
    if(obId>=0 && obId<MAX_OB_NUM)
    {
        ptrProcList[obId].push_back(ptrIn);
    }
       
}

void ob_manage::dettach(CProcedure * ptr,int obId)
{
    if(obId<0 || obId>=MAX_OB_NUM)
    {
        return;
    }

    if(ptrProcList[obId].empty())
    {
        return;
    }

    procList_T::iterator itProcNode = ptrProcList[obId].begin();

    while(itProcNode!=ptrProcList[obId].end())
    {
        if(*itProcNode == ptr)
        {
            ptrProcList[obId].erase(itProcNode);
            break;
        }
        itProcNode++;
    }
}

ob_manage::ob_manage()
{
    int i=0;
    for(i=0;i<MAX_OB_NUM;i++)
    {
        // procList_T::iterator itProcNode = ptrProcList[i].begin();
        // while(itProcNode!=ptrProcList[i].end())
        // {
        //      if(*itProcNode)
        //      {
        //         delete *itProcNode;
        //      }
        //      itProcNode++;
        // }
        ptrProcList[i].clear();
    }

    procListRunning.clear();
}

ob_manage::~ob_manage()
{
    int i=0;

    void * res;

    pthread_join(m_moduleThreadHandle,&res);
    for(i=0;i<MAX_OB_NUM;i++)
    {
        procList_T::iterator itProcNode = ptrProcList[i].begin();
        while(itProcNode!=ptrProcList[i].end())
        {
             if(*itProcNode)
             {
                delete *itProcNode;
             }
             itProcNode++;
        }
        ptrProcList[i].clear();
    }

    if(!procListRunning.empty())
    {
        procList_T::iterator itProcNode = procListRunning.begin();
        while(itProcNode!=procListRunning.end())
        {
            delete *itProcNode;
            itProcNode++;
        }
        procListRunning.clear();
    }
}

void ob_manage::update(void * dataIn)
{
    recvDataEleCtl * pstRecvDataIn = (recvDataEleCtl *)dataIn;
    int obId = convertEleCtlId(pstRecvDataIn->sid);
    //printf("in ob_manage::update, obId:%d\n",obId);
    if(obId>=MAX_OB_NUM)
    {
        return;
    }
    if(ptrProcList[obId].empty())
    {
        return;
    }
    procList_T::iterator itProcNode = ptrProcList[obId].begin();
    //int currNode = 0;
    int updateRet = 0;
    CProcedure * ptrProc = NULL;
    while(itProcNode!=ptrProcList[obId].end())
    {
        ptrProc = *itProcNode;

        ptrProc->updateOneProc(pstRecvDataIn);
        // currNode = ptrProc->getCurrProcNum();
        // if((*itProcNode)->procNodeArrHead[currNode].updateFunc)
        // {
        //     (*itProcNode)->procNodeArrHead[currNode].updateFunc(dataIn,&updateRet);
        // }       

        itProcNode++;
    }
}

void ob_manage::start(void)
{
    pthread_create(&m_moduleThreadHandle,NULL,moduleThread,this);
}

extern CCan * g_canHandle_can1;
void *moduleThread(void *paramIn)
{
    // moduleProcParam* pstPAram = (moduleProcParam*)paramIn;

    // if(pstPAram == NULL)
    // {
    //     return NULL;
    // }

    // CUim_MainCtl * pUimCtl = pstPAram->ptrUimCtl;
    // CRs485 * pRs485Ctl = pstPAram->ptrRs485;
    // CCan * pCanSubBoardCtl = pstPAram->ptrSubBoardCtl;
    ob_manage * ptrManage = (ob_manage *)paramIn;
    key_t key = ftok(msgQueueKeyPath, 0x1234);
    if(key < 0)
    {
        perror("ftok");
        return NULL;
    }

    int msg_id = msgget(key, IPC_CREAT);
    if(msg_id < 0)
    {
        perror("msgget");
    }
    printf("module proc thread started\n");
    g_msg_id = msg_id;
    module_queue_msg ctlMsg;

    int semRet = sem_init(&sem_liquid_detect,0,0);
    if(semRet!=0)
    {
        printf("sem init failed\n");
    }
    else
    {
        printf("sem init success\n");
    }
    flagLiquidCheck = 1;

    while(g_canHandle_can1 && !g_canHandle_can1->m_ExitThreadFlag)
    { 
       int lenRecv = msgrcv(msg_id, &ctlMsg, sizeof(module_msg), QUEUE_MSG_TYPE_MODULE, IPC_NOWAIT);
       if(lenRecv>0)
       {
           printf("recv module queue msg,module id is %d\n",ctlMsg.moduleMsg.moduleId);
        //here config for the procedure. and start procedure.
            switch (ctlMsg.moduleMsg.moduleId)
            {
                case I_FILE_OPENLID:
                {
                    set_for_openlid(ptrManage);
                    // sleep(2);
                    // msgQueueAck stMsgQueueAck;
                    // memset(&stMsgQueueAck,0,sizeof(msgQueueAck));
                    // stMsgQueueAck.type = QUEUE_MSG_TYPE_GRPC;
                    // stMsgQueueAck.msg.statusCode = 0;
                    // stMsgQueueAck.msg.moduleId = ctlMsg.moduleMsg.moduleId;
                    // stMsgQueueAck.msg.sid = 0xa5;
                    // if(msgsnd(g_msg_id, (void*)&stMsgQueueAck, sizeof(msgAck), 0) < 0)
                    // {
                    //     printf("send ack failed\n");
                    // }
                }                
                break;
                case I_FILE_CLOSELID:
                {
                    set_for_closelid(ptrManage);
                    // sleep(2);
                    // msgQueueAck stMsgQueueAck;
                    // memset(&stMsgQueueAck,0,sizeof(msgQueueAck));
                    // stMsgQueueAck.type = QUEUE_MSG_TYPE_GRPC;
                    // stMsgQueueAck.msg.statusCode = 0;
                    // stMsgQueueAck.msg.moduleId = ctlMsg.moduleMsg.moduleId;
                    // stMsgQueueAck.msg.sid = 0xa5;
                    // if(msgsnd(g_msg_id, (void*)&stMsgQueueAck, sizeof(msgAck), 0) < 0)
                    // {
                    //     printf("send ack failed\n");
                    // }

                }
                
                break;
                case I_FILE_XR:
                {
                    set_for_xr(ptrManage);
                    // sleep(2);
                    // msgQueueAck stMsgQueueAck;
                    // memset(&stMsgQueueAck,0,sizeof(msgQueueAck));
                    // stMsgQueueAck.type = QUEUE_MSG_TYPE_GRPC;
                    // stMsgQueueAck.msg.statusCode = 0;
                    // stMsgQueueAck.msg.moduleId = I_FILE_XR;
                    // stMsgQueueAck.msg.sid = 0xa5;
                    // if(msgsnd(g_msg_id, (void*)&stMsgQueueAck, sizeof(msgAck), 0) < 0)
                    // {
                    //     printf("send ack failed\n");
                    // }

                }                
                break;
                case I_FILE_BATH:
                {
                    set_for_bash(ptrManage);
                }                
                break;
                case I_FILE_TRANS:
                set_for_trans(ptrManage);
                break;                                
                case I_MODULE_BASHMOVE:
                set_for_bashmove(ptrManage);
                break;
                case I_FILE_DP8:
                set_for_dp8move(ptrManage);
                break;
                case I_MODULE_DP8SUCK:
                {
                    dp8_lld * ptrDp8lldMsg = &(ctlMsg.moduleMsg.un_param.dp8lldParam);
                    putToShareMem(ptrDp8lldMsg);
                    set_for_dp8suck(ptrManage);
                }                
                break;

                case I_MODULE_DP8DROPTIP:
                set_for_dp8droptip(ptrManage);
                break;

                case I_MODULE_DP8SPIT:
                set_for_dp8spit(ptrManage);
                break;

                case I_MODULE_DP8ONTIP:
                set_for_dp8installtip(ptrManage);
                break;

                case I_MODULE_BATHZMOVE:
                {
                    move_param * pstMoveParamIn = &ctlMsg.moduleMsg.un_param.moveParam;
                    move_param * pstMoveParam =  new move_param;
                    memcpy(pstMoveParam,pstMoveParamIn,sizeof(move_param));
                    printf("bathz,pos:%d,dec:%d,acc:%d,speed:%d\n",
                    pstMoveParam->pos,
                    pstMoveParam->dec_speed,
                    pstMoveParam->inc_speed,
                    pstMoveParam->speed);
                    set_for_bashz(ptrManage,pstMoveParam);
                }                
                break;
                case I_MODULE_BATH1ZMOVE:
                {
                    move_param * pstMoveParamIn = &ctlMsg.moduleMsg.un_param.moveParam;
                    move_param * pstMoveParam =  new move_param;
                    memcpy(pstMoveParam,pstMoveParamIn,sizeof(move_param));
                    printf("bathz1,pos:%d,dec:%d,acc:%d,speed:%d\n",
                    pstMoveParam->pos,
                    pstMoveParam->dec_speed,
                    pstMoveParam->inc_speed,
                    pstMoveParam->speed);
                    set_for_bashz1(ptrManage,pstMoveParam);
                }
                break;
                case I_FILE_THREMAL_SEAL:
                {
                    set_for_heat_seal(ptrManage);
                    // sleep(2);
                    // msgQueueAck stMsgQueueAck;
                    // memset(&stMsgQueueAck,0,sizeof(msgQueueAck));
                    // stMsgQueueAck.type = QUEUE_MSG_TYPE_GRPC;
                    // stMsgQueueAck.msg.statusCode = 0;
                    // stMsgQueueAck.msg.moduleId = I_FILE_THREMAL_SEAL;
                    // stMsgQueueAck.msg.sid = 0xa5;
                    // if(msgsnd(g_msg_id, (void*)&stMsgQueueAck, sizeof(msgAck), 0) < 0)
                    // {
                    //     printf("send ack failed\n");
                    // }
                }
                break;
                case I_FILE_DJ:
                {
                   dj_actParam djActParam;
                   dj_move_param * ptrDjMoveParam = &(ctlMsg.moduleMsg.un_param.djMoveParam);
                   djActParam.refPos.x = ptrDjMoveParam->initX;
                   djActParam.refPos.y = ptrDjMoveParam->initY;
                   djActParam.refPos.z = ptrDjMoveParam->initZ;
                   djActParam.deltaX = ptrDjMoveParam->deltaX;
                   djActParam.deltaY = ptrDjMoveParam->deltaY;
                   djActParam.numActOneCycle = ptrDjMoveParam->numStepsOneAct;
                   set_for_dj(ptrManage, &djActParam);
                }
                break;
                case I_MODULE_DJLIQUID:
                {
                   set_for_djclean(ptrManage, NULL);
                }
                break;
                case I_MODULE_DJREAGENT:
                {
                   dj_reagent * ptrQuantityMsg = &(ctlMsg.moduleMsg.un_param.djReagentParam);
                   dj_reagent * ptrQuantity =  new dj_reagent;
                   memcpy(ptrQuantity,ptrQuantityMsg,sizeof(dj_reagent));
                   modify_djreagent_xml(ptrQuantity);
                   delete ptrQuantity;
                   set_for_djreagent(ptrManage, NULL);
                }
                break;
				case I_MODULE_DP1TRANSTUBE:
				{
				   tube_trans * ptrTransTubeMsg = &(ctlMsg.moduleMsg.un_param.tubeTransParam);
                   tube_trans * ptrTransTubeParam =  new tube_trans;
                   memcpy(ptrTransTubeParam,ptrTransTubeMsg,sizeof(tube_trans));
                   set_for_transtube(ptrManage, ptrTransTubeParam);
				}
				break;
                case I_MODULE_DP8LLD:
                {
                    //set_for_dp8lld();
                    dp8_lld * ptrDp8lldMsg = &(ctlMsg.moduleMsg.un_param.dp8lldParam);
                    dp8_lld * ptrDp8lldParam = new dp8_lld;

                    memcpy(ptrDp8lldParam,ptrDp8lldMsg,sizeof(dp8_lld));

                    set_for_dp8lld(ptrDp8lldParam);

                }
                break;
                case I_MODULE_DP8SAMPLE:
                {
                    dp8capSample * ptrSampleMsg = &(ctlMsg.moduleMsg.un_param.dp8capSampleParam);
                    dp8capSample * ptrSampleParam = new dp8capSample;
                    memcpy(ptrSampleParam,ptrSampleMsg,sizeof(dp8capSample));
                    set_for_dp8capsample(ptrSampleParam);
                }
                break;

                default:
                break;
            }
           
       } 
       //move to a member function in ob_manage
       ptrManage->checkRunningProcs();   
       usleep(20000);
    }

    sem_destroy(&sem_liquid_detect);
}

void ob_manage::checkRunningProcs(void)
{
    if(!procListRunning.empty())
    {
        procList_T::iterator itProcNode = procListRunning.begin();
        procList_T::iterator itProcTmp;
        while(itProcNode!=procListRunning.end())
        {
            if((*itProcNode)->getDelFlag())
            {
                //printf("delete procNode now\n");
                delete *itProcNode;
                itProcTmp = itProcNode;
                itProcNode++;
                procListRunning.erase(itProcTmp);
                continue;
            }
            // else 
            // {
            //     printf("del flag is 0\n");
            // }
            itProcNode++;
        }
    }
}


void set_for_openlid(ob_manage * pManagerIn)
{
    CProcedure * ptrProc = new CProcedure();
    int numProc = 6;
    procNode * procArr = new procNode[numProc];
    memset(procArr,0,sizeof(procNode)*numProc);



    procArr[0].readParamFunc = openlid_gotoopen_read_param;              
    procArr[0].actFunc = openlid_gotoopen_act;
    procArr[0].queryFunc = openlid_gotoopen_query;              
    procArr[0].updateFunc = check_update;

    procArr[0].runtime = 3000000;//2000ms
    procArr[0].queryInterval = 200000;//200ms
    procArr[0].queryTimes = 5;


    procArr[1].readParamFunc = openlid_godown_read_param;              
    procArr[1].actFunc = openlid_godown_act;
    procArr[1].queryFunc = openlid_godown_query;              
    procArr[1].updateFunc = check_update;

    procArr[1].runtime = 8000000;//2000ms
    procArr[1].queryInterval = 200000;//200ms
    procArr[1].queryTimes = 5;

    procArr[2].readParamFunc = openlid_jawlid_read_param;              
    procArr[2].actFunc = openlid_jawlid_act;
    procArr[2].queryFunc = openlid_jawlid_query;              
    procArr[2].updateFunc = check_update;

    procArr[2].runtime = 1500000;//2000ms
    procArr[2].queryInterval = 200000;//200ms
    procArr[2].queryTimes = 5;

    procArr[3].readParamFunc = openlid_goup_read_param;              
    procArr[3].actFunc = openlid_goup_act;
    procArr[3].queryFunc = openlid_goup_query;              
    procArr[3].updateFunc = check_update;

    procArr[3].runtime = 4000000;//2000ms
    procArr[3].queryInterval = 200000;//200ms
    procArr[3].queryTimes = 5;

    

    procArr[4].readParamFunc = openlid_goreset_pre_read_param;              
    procArr[4].actFunc = lid_operation_act;
    procArr[4].queryFunc = openlid_goreset_query;              
    procArr[4].updateFunc = check_update;

    procArr[4].runtime = 4000000;//2000ms
    procArr[4].queryInterval = 200000;//200ms
    procArr[4].queryTimes = 5;

    procArr[5].readParamFunc = openlid_goreset_read_param;              
    procArr[5].actFunc = lid_operation_act;
    procArr[5].queryFunc = openlid_goreset_query;              
    procArr[5].updateFunc = check_update;

    procArr[5].runtime = 1500000;//2000ms
    procArr[5].queryInterval = 200000;//200ms
    procArr[5].queryTimes = 5;


    ptrProc->configProc(procArr,numProc);
    ptrProc->start(I_FILE_OPENLID);

    pManagerIn->procListRunning.push_back(ptrProc);
}

void set_for_openlid_back(ob_manage * pManagerIn)
{
    CProcedure * ptrProc = new CProcedure();
    int numProc = 8;
    procNode * procArr = new procNode[numProc];
    memset(procArr,0,sizeof(procNode)*numProc);
    procArr[0].readParamFunc = openlid_gotoscan_read_param;              
    procArr[0].actFunc = openlid_gotoscan_act;
    procArr[0].queryFunc = openlid_gotoscan_query;              
    procArr[0].updateFunc = check_update;

    procArr[0].runtime = 4000000;//2000ms
    procArr[0].queryInterval = 200000;//200ms
    procArr[0].queryTimes = 5;


    procArr[1].readParamFunc = openlid_scan_read_param;              
    procArr[1].actFunc = openlid_scan_act;
    procArr[1].queryFunc = openlid_scan_query;              
    procArr[1].updateFunc = check_update;

    procArr[1].runtime = 5000000;//2000ms
    procArr[1].queryInterval = 200000;//200ms
    procArr[1].queryTimes = 5;


    procArr[2].readParamFunc = openlid_gotoopen_read_param;              
    procArr[2].actFunc = openlid_gotoopen_act;
    procArr[2].queryFunc = openlid_gotoopen_query;              
    procArr[2].updateFunc = check_update;

    procArr[2].runtime = 3000000;//2000ms
    procArr[2].queryInterval = 200000;//200ms
    procArr[2].queryTimes = 5;


    procArr[3].readParamFunc = openlid_godown_read_param;              
    procArr[3].actFunc = openlid_godown_act;
    procArr[3].queryFunc = openlid_godown_query;              
    procArr[3].updateFunc = check_update;

    procArr[3].runtime = 8000000;//2000ms
    procArr[3].queryInterval = 200000;//200ms
    procArr[3].queryTimes = 5;

    procArr[4].readParamFunc = openlid_jawlid_read_param;              
    procArr[4].actFunc = openlid_jawlid_act;
    procArr[4].queryFunc = openlid_jawlid_query;              
    procArr[4].updateFunc = check_update;

    procArr[4].runtime = 1500000;//2000ms
    procArr[4].queryInterval = 200000;//200ms
    procArr[4].queryTimes = 5;

    procArr[5].readParamFunc = openlid_goup_read_param;              
    procArr[5].actFunc = openlid_goup_act;
    procArr[5].queryFunc = openlid_goup_query;              
    procArr[5].updateFunc = check_update;

    procArr[5].runtime = 4000000;//2000ms
    procArr[5].queryInterval = 200000;//200ms
    procArr[5].queryTimes = 5;

    

    procArr[6].readParamFunc = openlid_goreset_pre_read_param;              
    procArr[6].actFunc = lid_operation_act;
    procArr[6].queryFunc = openlid_goreset_query;              
    procArr[6].updateFunc = check_update;

    procArr[6].runtime = 1200000;//2000ms
    procArr[6].queryInterval = 200000;//200ms
    procArr[6].queryTimes = 5;

    procArr[7].readParamFunc = openlid_goreset_read_param;              
    procArr[7].actFunc = lid_operation_act;
    procArr[7].queryFunc = openlid_goreset_query;              
    procArr[7].updateFunc = check_update;

    procArr[7].runtime = 1500000;//2000ms
    procArr[7].queryInterval = 200000;//200ms
    procArr[7].queryTimes = 5;


    ptrProc->configProc(procArr,numProc);
    ptrProc->start(I_FILE_OPENLID);

    pManagerIn->procListRunning.push_back(ptrProc);
}


void set_for_closelid(ob_manage * pManagerIn)
{
    CProcedure * ptrProc = new CProcedure();
    int numProc = 6;
    procNode * procArr = new procNode[numProc];
    memset(procArr,0,sizeof(procNode)*numProc);
    procArr[0].readParamFunc = closelid_goopen_read_param;              
    procArr[0].actFunc = openlid_gotoscan_act;
    procArr[0].queryFunc = openlid_gotoscan_query;              
    procArr[0].updateFunc = check_update;

    procArr[0].runtime = 10000000;//2000ms
    procArr[0].queryInterval = 200000;//200ms
    procArr[0].queryTimes = 5;


    procArr[1].readParamFunc = closelid_godown_read_param;              
    procArr[1].actFunc = openlid_godown_act;
    procArr[1].queryFunc = openlid_godown_query;              
    procArr[1].updateFunc = check_update;

    procArr[1].runtime = 6000000;//2000ms
    procArr[1].queryInterval = 200000;//200ms
    procArr[1].queryTimes = 5;


    procArr[2].readParamFunc = closelid_jawlid_open_read_param;              
    procArr[2].actFunc = openlid_jawlid_act;
    procArr[2].queryFunc = openlid_jawlid_query;              
    procArr[2].updateFunc = check_update;

    procArr[2].runtime = 3000000;//2000ms
    procArr[2].queryInterval = 200000;//200ms
    procArr[2].queryTimes = 5;


    procArr[3].readParamFunc = closelid_goup_read_param;              
    procArr[3].actFunc = openlid_goup_act;
    procArr[3].queryFunc = openlid_goup_query;              
    procArr[3].updateFunc = check_update;

    procArr[3].runtime = 8000000;//2000ms
    procArr[3].queryInterval = 200000;//200ms
    procArr[3].queryTimes = 5;

    procArr[4].readParamFunc = closelid_goreset_pre_read_param;              
    procArr[4].actFunc = lid_operation_act;
    procArr[4].queryFunc = openlid_goreset_query;              
    procArr[4].updateFunc = check_update;

    procArr[4].runtime = 12000000;//2000ms
    procArr[4].queryInterval = 200000;//200ms
    procArr[4].queryTimes = 5;

    procArr[5].readParamFunc = closelid_goreset_read_param;              
    procArr[5].actFunc = lid_operation_act;
    procArr[5].queryFunc = openlid_goreset_query;              
    procArr[5].updateFunc = check_update;

    procArr[5].runtime = 6000000;//2000ms
    procArr[5].queryInterval = 200000;//200ms
    procArr[5].queryTimes = 5;


    ptrProc->configProc(procArr,numProc);
    ptrProc->start(I_FILE_CLOSELID);

    pManagerIn->procListRunning.push_back(ptrProc);
}

void set_for_xrAtoB(ob_manage * pManagerIn)
{
    CProcedure * ptrProc = new CProcedure();
    int numProc = 6;
    procNode * procArr = new procNode[numProc];
    memset(procArr,0,sizeof(procNode)*numProc);
    procArr[0].readParamFunc = xrAtoB_gotoB_read_param;              
    procArr[0].actFunc = lid_operation_act;
    procArr[0].queryFunc = openlid_gotoscan_query;              
    procArr[0].updateFunc = openlid_jawlid_update;

    procArr[0].runtime = 3000000;//2000ms
    procArr[0].queryInterval = 200000;//200ms
    procArr[0].queryTimes = 5;


    procArr[1].readParamFunc = xrAtoB_godown_read_param;              
    procArr[1].actFunc = lid_operation_act;
    procArr[1].queryFunc = openlid_gotoscan_query;              
    procArr[1].updateFunc = openlid_jawlid_update;

    procArr[1].runtime = 4000000;//2000ms
    procArr[1].queryInterval = 200000;//200ms
    procArr[1].queryTimes = 5;


    procArr[2].readParamFunc = xrAtoB_jawclose_read_param;              
    procArr[2].actFunc = lid_operation_act;
    procArr[2].queryFunc = openlid_gotoscan_query;              
    procArr[2].updateFunc = openlid_jawlid_update;

    procArr[2].runtime = 3000000;//2000ms
    procArr[2].queryInterval = 200000;//200ms
    procArr[2].queryTimes = 5;


    procArr[3].readParamFunc = xrAtoB_rotate_read_param;              
    procArr[3].actFunc = lid_operation_act;
    procArr[3].queryFunc = openlid_gotoscan_query;              
    procArr[3].updateFunc = openlid_jawlid_update;

    procArr[3].runtime = 4000000;//2000ms
    procArr[3].queryInterval = 200000;//200ms
    procArr[3].queryTimes = 5;

    procArr[4].readParamFunc = xrAtoB_jawopen_read_param;              
    procArr[4].actFunc = lid_operation_act;
    procArr[4].queryFunc = openlid_goreset_query;              
    procArr[4].updateFunc = openlid_jawlid_update;

    procArr[4].runtime = 3000000;//2000ms
    procArr[4].queryInterval = 200000;//200ms
    procArr[4].queryTimes = 5;

    procArr[5].readParamFunc = xrAtoB_goup_read_param;              
    procArr[5].actFunc = lid_operation_act;
    procArr[5].queryFunc = openlid_goreset_query;              
    procArr[5].updateFunc = openlid_jawlid_update;

    procArr[5].runtime = 5000000;//2000ms
    procArr[5].queryInterval = 200000;//200ms
    procArr[5].queryTimes = 5;


    ptrProc->configProc(procArr,numProc);
    ptrProc->start(I_FILE_XR);

    pManagerIn->procListRunning.push_back(ptrProc);
}

void set_for_bash(ob_manage * pManagerIn)
{
    printf("enter in set_for_bash\n");
    CProcedure * ptrProc = new CProcedure();
    int numProc = 1;
    procNode * procArr = new procNode[numProc];
    memset(procArr,0,sizeof(procNode)*numProc);
    procArr[0].readParamFunc = bash_read_param;              
    procArr[0].actFunc = lid_operation_act;
    procArr[0].queryFunc = openlid_gotoscan_query;              
    procArr[0].updateFunc = openlid_jawlid_update;

    procArr[0].runtime = 30000000;//2000ms
    procArr[0].queryInterval = 200000;//200ms
    procArr[0].queryTimes = 5;

    ptrProc->configProc(procArr,numProc);
    ptrProc->start(I_FILE_BATH);

    pManagerIn->procListRunning.push_back(ptrProc);
}

void set_for_bashz(ob_manage * pManagerIn, void * pstMoveParam)
{
    printf("enter in set_for_bashz\n");
    CProcedure * ptrProc = new CProcedure();
    int numProc = 1;
    procNode * procArr = new procNode[numProc];
    memset(procArr,0,sizeof(procNode)*numProc);
    procArr[0].readParamFunc = bashzmove_read_param;              
    procArr[0].actFunc = lid_operation_act;
    procArr[0].queryFunc = openlid_gotoscan_query;              
    procArr[0].updateFunc = check_update;

    procArr[0].runtime = 30000000;//2000ms
    procArr[0].queryInterval = 200000;//200ms
    procArr[0].queryTimes = 5;


    ptrProc->setParamIn( PARAM_FOR_BASHZ,pstMoveParam);

    ptrProc->configProc(procArr,numProc);
    ptrProc->start(I_MODULE_BATHZMOVE);

    pManagerIn->procListRunning.push_back(ptrProc);
}

void set_for_bashz1(ob_manage * pManagerIn, void * pstMoveParam)
{
    printf("enter in set_for_bashz1\n");
    CProcedure * ptrProc = new CProcedure();
    int numProc = 1;
    procNode * procArr = new procNode[numProc];
    memset(procArr,0,sizeof(procNode)*numProc);
    procArr[0].readParamFunc = bash1zmove_read_param;              
    procArr[0].actFunc = lid_operation_act;
    procArr[0].queryFunc = openlid_gotoscan_query;              
    procArr[0].updateFunc = check_update;

    procArr[0].runtime = 40000000;//2000ms
    procArr[0].queryInterval = 200000;//200ms
    procArr[0].queryTimes = 5;


    ptrProc->setParamIn( PARAM_FOR_BASHZ,pstMoveParam);

    ptrProc->configProc(procArr,numProc);
    ptrProc->start(I_MODULE_BATH1ZMOVE);

    pManagerIn->procListRunning.push_back(ptrProc);
}

void set_for_trans(ob_manage * pManagerIn)
{
    CProcedure * ptrProc = new CProcedure();
    int numProc = 7;
    procNode * procArr = new procNode[numProc];
    memset(procArr,0,sizeof(procNode)*numProc);
    // procArr[0].readParamFunc = trans_gotoYend_read_param;              
    // procArr[0].actFunc = lid_operation_act;
    // procArr[0].queryFunc = openlid_gotoscan_query;              
    // procArr[0].updateFunc = openlid_jawlid_update;

    // procArr[0].runtime = 10000000;//2000ms
    // procArr[0].queryInterval = 200000;//200ms
    // procArr[0].queryTimes = 5;


    // procArr[1].readParamFunc = trans_godown_read_param;              
    // procArr[1].actFunc = lid_operation_act;
    // procArr[1].queryFunc = openlid_gotoscan_query;              
    // procArr[1].updateFunc = openlid_jawlid_update;

    // procArr[1].runtime = 10000000;//2000ms
    // procArr[1].queryInterval = 200000;//200ms
    // procArr[1].queryTimes = 5;


    // procArr[2].readParamFunc = trans_jawclose_read_param;              
    // procArr[2].actFunc = lid_operation_act;
    // procArr[2].queryFunc = openlid_gotoscan_query;              
    // procArr[2].updateFunc = openlid_jawlid_update;

    // procArr[2].runtime = 3000000;//2000ms
    // procArr[2].queryInterval = 200000;//200ms
    // procArr[2].queryTimes = 5;


    // procArr[3].readParamFunc = trans_goup_read_param;              
    // procArr[3].actFunc = lid_operation_act;
    // procArr[3].queryFunc = openlid_gotoscan_query;              
    // procArr[3].updateFunc = openlid_jawlid_update;

    // procArr[3].runtime = 4000000;//2000ms
    // procArr[3].queryInterval = 200000;//200ms
    // procArr[3].queryTimes = 5;

    // procArr[4].readParamFunc = trans_gotoYstart_read_param;              
    // procArr[4].actFunc = lid_operation_act;
    // procArr[4].queryFunc = openlid_goreset_query;              
    // procArr[4].updateFunc = openlid_jawlid_update;

    // procArr[4].runtime = 10000000;//2000ms
    // procArr[4].queryInterval = 200000;//200ms
    // procArr[4].queryTimes = 5;

    // procArr[5].readParamFunc = trans_bashgodown_read_param;              
    // procArr[5].actFunc = lid_operation_act;
    // procArr[5].queryFunc = openlid_goreset_query;              
    // procArr[5].updateFunc = openlid_jawlid_update;

    // procArr[5].runtime = 5000000;//2000ms
    // procArr[5].queryInterval = 200000;//200ms
    // procArr[5].queryTimes = 5;

    // procArr[6].readParamFunc = trans_xgoend_read_param;              
    // procArr[6].actFunc = lid_operation_act;
    // procArr[6].queryFunc = openlid_goreset_query;              
    // procArr[6].updateFunc = openlid_jawlid_update;

    // procArr[6].runtime = 10000000;//2000ms
    // procArr[6].queryInterval = 200000;//200ms
    // procArr[6].queryTimes = 5;
    
    // procArr[7].readParamFunc = trans_jawopen_read_param;              
    // procArr[7].actFunc = lid_operation_act;
    // procArr[7].queryFunc = openlid_goreset_query;              
    // procArr[7].updateFunc = openlid_jawlid_update;

    // procArr[7].runtime = 5000000;//2000ms
    // procArr[7].queryInterval = 200000;//200ms
    // procArr[7].queryTimes = 5;

    // procArr[8].readParamFunc = trans_xgotoheat_read_param;              
    // procArr[8].actFunc = lid_operation_act;
    // procArr[8].queryFunc = openlid_goreset_query;              
    // procArr[8].updateFunc = openlid_jawlid_update;

    // procArr[8].runtime = 8000000;//2000ms
    // procArr[8].queryInterval = 200000;//200ms
    // procArr[8].queryTimes = 5;

    // procArr[9].readParamFunc = trans_bashgoup_read_param;              
    // procArr[9].actFunc = lid_operation_act;
    // procArr[9].queryFunc = openlid_goreset_query;              
    // procArr[9].updateFunc = openlid_jawlid_update;

    // procArr[10].runtime = 5000000;//2000ms
    // procArr[10].queryInterval = 200000;//200ms
    // procArr[10].queryTimes = 5;

    // procArr[10].readParamFunc = trans_goreset_read_param;              
    // procArr[10].actFunc = lid_operation_act;
    // procArr[10].queryFunc = openlid_goreset_query;              
    // procArr[10].updateFunc = trans_goreset_update;

    // procArr[10].runtime = 5000000;//2000ms
    // procArr[10].queryInterval = 200000;//200ms
    // procArr[10].queryTimes = 5;

    procArr[0].readParamFunc = trans_gotoYend_read_param;              
    procArr[0].actFunc = lid_operation_act;
    procArr[0].queryFunc = openlid_gotoscan_query;              
    procArr[0].updateFunc = check_update;

    procArr[0].runtime = 20000000;//2000ms
    procArr[0].queryInterval = 200000;//200ms
    procArr[0].queryTimes = 5;


    procArr[1].readParamFunc = trans_godown_read_param;              
    procArr[1].actFunc = lid_operation_act;
    procArr[1].queryFunc = openlid_gotoscan_query;              
    procArr[1].updateFunc = check_update;

    procArr[1].runtime = 30000000;//2000ms
    procArr[1].queryInterval = 200000;//200ms
    procArr[1].queryTimes = 5;


    procArr[2].readParamFunc = trans_jawclose_read_param;              
    procArr[2].actFunc = lid_operation_act;
    procArr[2].queryFunc = openlid_gotoscan_query;              
    procArr[2].updateFunc = check_update;

    procArr[2].runtime = 10000000;//2000ms
    procArr[2].queryInterval = 200000;//200ms
    procArr[2].queryTimes = 5;


    procArr[3].readParamFunc = trans_goup_read_param;              
    procArr[3].actFunc = lid_operation_act;
    procArr[3].queryFunc = openlid_gotoscan_query;              
    procArr[3].updateFunc = check_update;

    procArr[3].runtime = 40000000;//2000ms
    procArr[3].queryInterval = 200000;//200ms
    procArr[3].queryTimes = 5;

    procArr[4].readParamFunc = trans_gotoYstart_read_param;              
    procArr[4].actFunc = lid_operation_act;
    procArr[4].queryFunc = openlid_goreset_query;              
    procArr[4].updateFunc = check_update;

    procArr[4].runtime = 30000000;//2000ms
    procArr[4].queryInterval = 200000;//200ms
    procArr[4].queryTimes = 5;

    procArr[5].readParamFunc = trans_jawopen_read_param;              
    procArr[5].actFunc = lid_operation_act;
    procArr[5].queryFunc = openlid_goreset_query;              
    procArr[5].updateFunc = check_update;

    procArr[5].runtime = 10000000;//2000ms
    procArr[5].queryInterval = 200000;//200ms
    procArr[5].queryTimes = 5;

    procArr[6].readParamFunc = trans_goreset_read_param;              
    procArr[6].actFunc = lid_operation_act;
    procArr[6].queryFunc = openlid_goreset_query;              
    procArr[6].updateFunc = check_update;

    procArr[6].runtime = 20000000;//2000ms
    procArr[6].queryInterval = 200000;//200ms
    procArr[6].queryTimes = 5;


    ptrProc->configProc(procArr,numProc);
    ptrProc->start(I_FILE_TRANS);

    pManagerIn->procListRunning.push_back(ptrProc);
}

void set_for_bashmove(ob_manage * pManagerIn)
{
    CProcedure * ptrProc = new CProcedure();
    int numProc = 4;
    procNode * procArr = new procNode[numProc];
    memset(procArr,0,sizeof(procNode)*numProc);
    procArr[0].readParamFunc = trans_bashgodown_read_param;              
    procArr[0].actFunc = lid_operation_act;
    procArr[0].queryFunc = openlid_gotoscan_query;              
    procArr[0].updateFunc = check_update;

    procArr[0].runtime = 10000000;//2000ms
    procArr[0].queryInterval = 200000;//200ms
    procArr[0].queryTimes = 5;


    procArr[1].readParamFunc = trans_xgoend_read_param;              
    procArr[1].actFunc = lid_operation_act;
    procArr[1].queryFunc = openlid_gotoscan_query;              
    procArr[1].updateFunc = check_update;

    procArr[1].runtime = 10000000;//2000ms
    procArr[1].queryInterval = 200000;//200ms
    procArr[1].queryTimes = 5;


    procArr[2].readParamFunc = trans_xgotoheat_read_param;              
    procArr[2].actFunc = lid_operation_act;
    procArr[2].queryFunc = openlid_gotoscan_query;              
    procArr[2].updateFunc = check_update;

    procArr[2].runtime = 5000000;//2000ms
    procArr[2].queryInterval = 200000;//200ms
    procArr[2].queryTimes = 5;


    procArr[3].readParamFunc = trans_bashgoup_read_param;              
    procArr[3].actFunc = lid_operation_act;
    procArr[3].queryFunc = openlid_gotoscan_query;              
    procArr[3].updateFunc = check_update;

    procArr[3].runtime = 10000000;//2000ms
    procArr[3].queryInterval = 200000;//200ms
    procArr[3].queryTimes = 5;

    

    ptrProc->configProc(procArr,numProc);
    ptrProc->start(I_MODULE_BASHMOVE);

    pManagerIn->procListRunning.push_back(ptrProc);
}

void set_for_dp8move(ob_manage * pManagerIn)
{
    CProcedure * ptrProc = new CProcedure();
    int numProc = 3;
    procNode * procArr = new procNode[numProc];
    memset(procArr,0,sizeof(procNode)*numProc);
    
    procArr[0].readParamFunc = dp8_zret_read_param;              
    procArr[0].actFunc = lid_operation_act;
    procArr[0].queryFunc = openlid_gotoscan_query;              
    procArr[0].updateFunc = check_update;

    procArr[0].runtime = 60000000;//2000ms
    procArr[0].queryInterval = 200000;//200ms
    procArr[0].queryTimes = 5;

    procArr[1].readParamFunc = dp8_loc_horizen_read_param;              
    procArr[1].actFunc = lid_operation_act;//dp8_move_xy;
    procArr[1].queryFunc = openlid_gotoscan_query;              
    procArr[1].updateFunc = check_update;

    procArr[1].runtime = 300000000;//2000ms
    procArr[1].queryInterval = 200000;//200ms
    procArr[1].queryTimes = 5;


    procArr[2].readParamFunc = dp8_loc_vertical_read_param;              
    procArr[2].actFunc = lid_operation_act;
    procArr[2].queryFunc = openlid_gotoscan_query;              
    procArr[2].updateFunc = check_update;

    procArr[2].runtime = 20000000;//2000ms
    procArr[2].queryInterval = 200000;//200ms
    procArr[2].queryTimes = 5;
    

    ptrProc->configProc(procArr,numProc);
    ptrProc->start(I_FILE_DP8);

    pManagerIn->procListRunning.push_back(ptrProc);
}

void set_for_dp8suck(ob_manage * pManagerIn)
{
    CProcedure * ptrProc = new CProcedure();
    int numProc = 3;
    procNode * procArr = new procNode[numProc];
    memset(procArr,0,sizeof(procNode)*numProc);
    procArr[0].readParamFunc = dp8_probe_read_param;              
    procArr[0].actFunc = liquid_probe_act;//this function should be special written
    procArr[0].queryFunc = openlid_gotoscan_query;              
    procArr[0].updateFunc = check_update;

    procArr[0].runtime = 10000000;//2000ms
    procArr[0].queryInterval = 200000;//200ms
    procArr[0].queryTimes = 5;


    procArr[1].readParamFunc = dp8_suckact_read_param;              
    procArr[1].actFunc = liquid_suck_act;
    procArr[1].queryFunc = openlid_gotoscan_query;              
    procArr[1].updateFunc = check_update;

    procArr[1].runtime = 5000000;//2000ms
    procArr[1].queryInterval = 200000;//200ms
    procArr[1].queryTimes = 5;


    procArr[2].readParamFunc = dp8_suckend_read_param;              
    procArr[2].actFunc = lid_operation_act;
    procArr[2].queryFunc = openlid_gotoscan_query;              
    procArr[2].updateFunc = check_update;

    procArr[2].runtime = 12000000;//2000ms
    procArr[2].queryInterval = 200000;//200ms
    procArr[2].queryTimes = 5;
    

    ptrProc->configProc(procArr,numProc);
    ptrProc->start(I_MODULE_DP8SUCK);

    pManagerIn->procListRunning.push_back(ptrProc);
}

void set_for_dp8droptip(ob_manage * pManagerIn)
{
    CProcedure * ptrProc = new CProcedure();
    int numProc = 2;
    procNode * procArr = new procNode[numProc];
    memset(procArr,0,sizeof(procNode)*numProc);
    procArr[0].readParamFunc = dp8_droptip_down_read_param;              
    procArr[0].actFunc = lid_operation_act;
    procArr[0].queryFunc = openlid_gotoscan_query;              
    procArr[0].updateFunc = check_update;

    procArr[0].runtime = 12000000;//2000ms
    procArr[0].queryInterval = 200000;//200ms
    procArr[0].queryTimes = 5;


    procArr[1].readParamFunc = dp8_droptip_up_read_param;              
    procArr[1].actFunc = lid_operation_act;
    procArr[1].queryFunc = openlid_gotoscan_query;              
    procArr[1].updateFunc = check_update;

    procArr[1].runtime = 20000000;//2000ms
    procArr[1].queryInterval = 200000;//200ms
    procArr[1].queryTimes = 5;
    

    ptrProc->configProc(procArr,numProc);
    ptrProc->start(I_MODULE_DP8DROPTIP);

    pManagerIn->procListRunning.push_back(ptrProc);
}

void set_for_dp8spit(ob_manage * pManagerIn)
{
    CProcedure * ptrProc = new CProcedure();
    int numProc = 2;
    procNode * procArr = new procNode[numProc];
    memset(procArr,0,sizeof(procNode)*numProc);
    procArr[0].readParamFunc = dp8_split_down_read_param;              
    procArr[0].actFunc = lid_operation_act;
    procArr[0].queryFunc = openlid_gotoscan_query;              
    procArr[0].updateFunc = check_update;

    procArr[0].runtime = 10000000;//2000ms
    procArr[0].queryInterval = 200000;//200ms
    procArr[0].queryTimes = 5;


    procArr[1].readParamFunc = dp8_split_up_read_param;              
    procArr[1].actFunc = lid_operation_act;
    procArr[1].queryFunc = openlid_gotoscan_query;              
    procArr[1].updateFunc = check_update;

    procArr[1].runtime = 5000000;//2000ms
    procArr[1].queryInterval = 200000;//200ms
    procArr[1].queryTimes = 5;
    

    ptrProc->configProc(procArr,numProc);
    ptrProc->start(I_MODULE_DP8SPIT);

    pManagerIn->procListRunning.push_back(ptrProc);
}

void set_for_dp8installtip(ob_manage * pManagerIn)
{
    CProcedure * ptrProc = new CProcedure();
    int numProc = 2;
    procNode * procArr = new procNode[numProc];
    memset(procArr,0,sizeof(procNode)*numProc);
    procArr[0].readParamFunc = dp8_ontip_down_read_param;              
    procArr[0].actFunc = lid_operation_act;
    procArr[0].queryFunc = openlid_gotoscan_query;              
    procArr[0].updateFunc = check_update;

    procArr[0].runtime = 10000000;//2000ms
    procArr[0].queryInterval = 200000;//200ms
    procArr[0].queryTimes = 5;


    procArr[1].readParamFunc = dp8_ontip_up_read_param;              
    procArr[1].actFunc = lid_operation_act;
    procArr[1].queryFunc = openlid_gotoscan_query;              
    procArr[1].updateFunc = check_update;

    procArr[1].runtime = 50000000;//2000ms
    procArr[1].queryInterval = 200000;//200ms
    procArr[1].queryTimes = 5;
    

    ptrProc->configProc(procArr,numProc);
    ptrProc->start(I_MODULE_DP8ONTIP);

    pManagerIn->procListRunning.push_back(ptrProc);
}

void set_for_xr(ob_manage * pManagerIn)
{
    CProcedure * ptrProc = new CProcedure();
    int numProc = 12;
    procNode * procArr = new procNode[numProc];
    memset(procArr,0,sizeof(procNode)*numProc);

    procArr[0].readParamFunc = xr_gotoStartY2_read_param;              
    procArr[0].actFunc = lid_operation_act;
    procArr[0].queryFunc = openlid_gotoscan_query;              
    procArr[0].updateFunc = check_update;

    procArr[0].runtime = 10000000;//2000ms
    procArr[0].queryInterval = 200000;//200ms
    procArr[0].queryTimes = 5;

    procArr[1].readParamFunc = xr_gotoStartY_read_param;              
    procArr[1].actFunc = lid_operation_act;
    procArr[1].queryFunc = openlid_gotoscan_query;              
    procArr[1].updateFunc = check_update;

    procArr[1].runtime = 10000000;//2000ms
    procArr[1].queryInterval = 200000;//200ms
    procArr[1].queryTimes = 5;


    procArr[2].readParamFunc = xr_startRotate_read_param;              
    procArr[2].actFunc = lid_operation_act;
    procArr[2].queryFunc = openlid_gotoscan_query;              
    procArr[2].updateFunc = check_update;

    procArr[2].runtime = 5000000;//2000ms
    procArr[2].queryInterval = 200000;//200ms
    procArr[2].queryTimes = 5;

    procArr[3].readParamFunc = xr_startDown_read_param;              
    procArr[3].actFunc = lid_operation_act;
    procArr[3].queryFunc = openlid_gotoscan_query;              
    procArr[3].updateFunc = check_update;

    procArr[3].runtime = 5000000;//2000ms
    procArr[3].queryInterval = 200000;//200ms
    procArr[3].queryTimes = 5;

    procArr[4].readParamFunc = xr_jawclose_read_param;              
    procArr[4].actFunc = lid_operation_act;
    procArr[4].queryFunc = openlid_gotoscan_query;              
    procArr[4].updateFunc = check_update;

    procArr[4].runtime = 5000000;//2000ms
    procArr[4].queryInterval = 200000;//200ms
    procArr[4].queryTimes = 5;

    procArr[5].readParamFunc = xr_rotate_read_param;              
    procArr[5].actFunc = lid_operation_act;
    procArr[5].queryFunc = openlid_gotoscan_query;              
    procArr[5].updateFunc = check_update;

    procArr[5].runtime = 5000000;//2000ms
    procArr[5].queryInterval = 200000;//200ms
    procArr[5].queryTimes = 5;

    procArr[6].readParamFunc = xr_gotoTarY_read_param;              
    procArr[6].actFunc = lid_operation_act;
    procArr[6].queryFunc = openlid_gotoscan_query;              
    procArr[6].updateFunc = check_update;

    procArr[6].runtime = 5000000;//2000ms
    procArr[6].queryInterval = 200000;//200ms
    procArr[6].queryTimes = 5;

    procArr[7].readParamFunc = xr_gotoTarY2_read_param;              
    procArr[7].actFunc = lid_operation_act;
    procArr[7].queryFunc = openlid_gotoscan_query;              
    procArr[7].updateFunc = check_update;

    procArr[7].runtime = 5000000;//2000ms
    procArr[7].queryInterval = 200000;//200ms
    procArr[7].queryTimes = 5;


    procArr[8].readParamFunc = xr_downTar_read_param;              
    procArr[8].actFunc = lid_operation_act;
    procArr[8].queryFunc = openlid_gotoscan_query;              
    procArr[8].updateFunc = check_update;

    procArr[8].runtime = 5000000;//2000ms
    procArr[8].queryInterval = 200000;//200ms
    procArr[8].queryTimes = 5;

    procArr[9].readParamFunc = xr_jawopen_read_param;              
    procArr[9].actFunc = lid_operation_act;
    procArr[9].queryFunc = openlid_gotoscan_query;              
    procArr[9].updateFunc = check_update;

    procArr[9].runtime = 5000000;//2000ms
    procArr[9].queryInterval = 200000;//200ms
    procArr[9].queryTimes = 5;

    procArr[10].readParamFunc = xr_goreset_read_param;              
    procArr[10].actFunc = lid_operation_act;
    procArr[10].queryFunc = openlid_gotoscan_query;              
    procArr[10].updateFunc = check_update;

    procArr[10].runtime = 5000000;//2000ms
    procArr[10].queryInterval = 200000;//200ms
    procArr[10].queryTimes = 5;

    procArr[11].readParamFunc = xr_goreset2_read_param;              
    procArr[11].actFunc = lid_operation_act;
    procArr[11].queryFunc = openlid_gotoscan_query;              
    procArr[11].updateFunc = check_update;

    procArr[11].runtime = 5000000;//2000ms
    procArr[11].queryInterval = 200000;//200ms
    procArr[11].queryTimes = 5;    

    ptrProc->configProc(procArr,numProc);
    ptrProc->start(I_FILE_XR);

    pManagerIn->procListRunning.push_back(ptrProc);
}

void set_for_heat_seal(ob_manage * pManagerIn)
{
    CProcedure * ptrProc = new CProcedure();
    int numProc = 7;
    procNode * procArr = new procNode[numProc];
    memset(procArr,0,sizeof(procNode)*numProc);
    procArr[0].readParamFunc = heatSeal_gotosafe_read_param;              
    procArr[0].actFunc = lid_operation_act;
    procArr[0].queryFunc = openlid_gotoscan_query;              
    procArr[0].updateFunc = check_update;

    procArr[0].runtime = 10000000;//2000ms
    procArr[0].queryInterval = 200000;//200ms
    procArr[0].queryTimes = 5;


    procArr[1].readParamFunc = heatSeal_xrRotate_read_param;              
    procArr[1].actFunc = lid_operation_act;
    procArr[1].queryFunc = openlid_gotoscan_query;              
    procArr[1].updateFunc = check_update;

    procArr[1].runtime = 5000000;//2000ms
    procArr[1].queryInterval = 200000;//200ms
    procArr[1].queryTimes = 5;


    procArr[2].readParamFunc = heatSeal_gotoheat_read_param;              
    procArr[2].actFunc = lid_operation_act;
    procArr[2].queryFunc = openlid_gotoscan_query;              
    procArr[2].updateFunc = check_update;

    procArr[2].runtime = 5000000;//2000ms
    procArr[2].queryInterval = 200000;//200ms
    procArr[2].queryTimes = 5;

    procArr[3].readParamFunc = heatSeal_heatdown_read_param;              
    procArr[3].actFunc = lid_operation_act;
    procArr[3].queryFunc = openlid_gotoscan_query;              
    procArr[3].updateFunc = check_update;

    procArr[3].runtime = 5000000;//2000ms
    procArr[3].queryInterval = 200000;//200ms
    procArr[3].queryTimes = 5;

    procArr[4].readParamFunc = heatSeal_heatup_read_param;              
    procArr[4].actFunc = lid_operation_act;
    procArr[4].queryFunc = openlid_gotoscan_query;              
    procArr[4].updateFunc = check_update;

    procArr[4].runtime = 5000000;//2000ms
    procArr[4].queryInterval = 200000;//200ms
    procArr[4].queryTimes = 5;

    procArr[5].readParamFunc = heatSeal_goreset_read_param;              
    procArr[5].actFunc = lid_operation_act;
    procArr[5].queryFunc = openlid_gotoscan_query;              
    procArr[5].updateFunc = check_update;

    procArr[5].runtime = 5000000;//2000ms
    procArr[5].queryInterval = 200000;//200ms
    procArr[5].queryTimes = 5;

    procArr[6].readParamFunc = heatSeal_rotate_reset_read_param;              
    procArr[6].actFunc = lid_operation_act;
    procArr[6].queryFunc = openlid_gotoscan_query;              
    procArr[6].updateFunc = check_update;

    procArr[6].runtime = 5000000;//2000ms
    procArr[6].queryInterval = 200000;//200ms
    procArr[6].queryTimes = 5;    

    ptrProc->configProc(procArr,numProc);
    ptrProc->start(I_FILE_THREMAL_SEAL);

    pManagerIn->procListRunning.push_back(ptrProc);
}



void set_for_dj(ob_manage * pManagerIn, void * actParamIn)
{
    if(actParamIn==NULL || pManagerIn==NULL)
    {
        return;
    }
    dj_actParam * actParam = (dj_actParam * )actParamIn;
    CProcedure_Dj * ptrProc = new CProcedure_Dj();
    int numProc = actParam->numActOneCycle;
    procNode * procArr = new procNode[numProc];
    memset(procArr,0,sizeof(procNode)*numProc);


    for(int i=0;i<numProc;i++)
    {
        procArr[i].readParamFunc = NULL;
        if(i==(numProc-1))
        {
            procArr[i].actFunc = dj_pump_spit_act;
        }
        else
        {
            procArr[i].actFunc = lid_operation_act;
        }
        
        procArr[i].queryFunc = openlid_gotoscan_query;
        procArr[i].updateFunc = check_update;

        procArr[i].runtime = 8000000;//2000ms
        procArr[i].queryInterval = 200000;//200ms
        procArr[i].queryTimes = 5;
    }

    printf("refpos x:%d,y:%d,z:%d\n",
    actParam->refPos.x,
    actParam->refPos.y,
    actParam->refPos.z);

    printf("deltax:%d,deltay:%d\n",
    actParam->deltaX,
    actParam->deltaY
    );
    

    FILE * fp = fopen(FILE_DJ_TRACE,"r");

    if(fp==NULL)
    {
        delete [] procArr;
        delete ptrProc;
        return;
    }
    else
    {
        char buffFromFile[1024];
        memset(buffFromFile,0,1024);
        fgets(buffFromFile,1024,fp);       
        

        fclose(fp);
        ptrProc->setMoveTrace(buffFromFile,strlen(buffFromFile),actParam);
    }
    
    
    ptrProc->configProc(procArr,numProc);
    ptrProc->start_dj(I_FILE_DJ);

    pManagerIn->procListRunning.push_back(ptrProc);
    //delete [] procArr;
    //delete ptrProc;
    
}

void set_for_djclean(ob_manage * pManagerIn, void * actParamIn)
{
    CProcedure * ptrProc = new CProcedure();
    int numProc = 13;
    procNode * procArr = new procNode[numProc];
    memset(procArr,0,sizeof(procNode)*numProc);
    djcleanParamCtl * ptrParamCtl = new djcleanParamCtl[numProc];
    memset(ptrParamCtl,0,sizeof(djcleanParamCtl)*numProc);
    const int eleType[13] = {0,0,0,1,1,1,1,0,1,1,1,1,0};

    ptrProc->setParamIn(PARAM_FOR_DJCLEAN,ptrParamCtl);


    for(int i=0;i<numProc;i++)
    {
        procArr[i].readParamFunc = NULL;//djclean_read_param;              
        procArr[i].actFunc = lid_operation_act;
        procArr[i].queryFunc = openlid_gotoscan_query;              
        procArr[i].updateFunc = check_update;

        procArr[i].runtime = 5000000;//2000ms
        procArr[i].queryInterval = 200000;//200ms
        procArr[i].queryTimes = 5;

        ptrParamCtl[i].eleType = eleType[i];
        ptrParamCtl[i].stepNum = i+1;
    }
    

    ptrProc->configProc(procArr,numProc);
    ptrProc->start(I_MODULE_DJLIQUID);

    pManagerIn->procListRunning.push_back(ptrProc);
}


void set_for_djreagent(ob_manage * pManagerIn, void * actParam)
{
    CProcedure * ptrProc = new CProcedure();
    int numProc = 7;
    procNode * procArr = new procNode[numProc];
    memset(procArr,0,sizeof(procNode)*numProc);
    
    procArr[0].readParamFunc = djreagnet_reset0_read_param;              
    procArr[0].actFunc = lid_operation_act;
    procArr[0].queryFunc = openlid_gotoscan_query;              
    procArr[0].updateFunc = check_update;

    procArr[0].runtime = 5000000;//2000ms
    procArr[0].queryInterval = 200000;//200ms
    procArr[0].queryTimes = 5;


    procArr[1].readParamFunc = djreagnet_gotoreagent_read_param;              
    procArr[1].actFunc = lid_operation_act;
    procArr[1].queryFunc = openlid_gotoscan_query;              
    procArr[1].updateFunc = check_update;

    procArr[1].runtime = 5000000;//2000ms
    procArr[1].queryInterval = 200000;//200ms
    procArr[1].queryTimes = 5;


    procArr[2].readParamFunc = djreagnet_suck_air_read_param;              
    procArr[2].actFunc = dj_pump_suck_act;
    procArr[2].queryFunc = openlid_gotoscan_query;              
    procArr[2].updateFunc = check_update;

    procArr[2].runtime = 5000000;//2000ms
    procArr[2].queryInterval = 200000;//200ms
    procArr[2].queryTimes = 5;

    procArr[3].readParamFunc = djreagnet_zgodown_read_param;              
    procArr[3].actFunc = lid_operation_act;
    procArr[3].queryFunc = openlid_gotoscan_query;              
    procArr[3].updateFunc = check_update;

    procArr[3].runtime = 5000000;//2000ms
    procArr[3].queryInterval = 200000;//200ms
    procArr[3].queryTimes = 5;

    procArr[4].readParamFunc = djreagnet_suck_reagent_read_param;              
    procArr[4].actFunc = dj_pump_suck_act;
    procArr[4].queryFunc = openlid_gotoscan_query;              
    procArr[4].updateFunc = check_update;

    procArr[4].runtime = 5000000;//2000ms
    procArr[4].queryInterval = 200000;//200ms
    procArr[4].queryTimes = 5;

    procArr[5].readParamFunc = djreagnet_spit_reagent_read_param;              
    procArr[5].actFunc = dj_pump_spit_act;
    procArr[5].queryFunc = openlid_gotoscan_query;              
    procArr[5].updateFunc = check_update;

    procArr[5].runtime = 5000000;//2000ms
    procArr[5].queryInterval = 200000;//200ms
    procArr[5].queryTimes = 5;

    procArr[6].readParamFunc = djreagnet_zreset_read_param;              
    procArr[6].actFunc = lid_operation_act;
    procArr[6].queryFunc = openlid_gotoscan_query;              
    procArr[6].updateFunc = check_update;

    procArr[6].runtime = 5000000;//2000ms
    procArr[6].queryInterval = 200000;//200ms
    procArr[6].queryTimes = 5;
    
    

    ptrProc->configProc(procArr,numProc);
    ptrProc->start(I_MODULE_DJREAGENT);

    pManagerIn->procListRunning.push_back(ptrProc);
}

void set_for_transtube(ob_manage * pManagerIn, void * actParam)
{
    CProcedure * ptrProc = new CProcedure();
    int numProc = 9;
    procNode * procArr = new procNode[numProc];
    memset(procArr,0,sizeof(procNode)*numProc);

    ptrProc->setParamIn(PARAM_FOR_TRANSTUBE,actParam);
    
    procArr[0].readParamFunc = transtube_jawzret_read_param;              
    procArr[0].actFunc = lid_operation_act;
    procArr[0].queryFunc = openlid_gotoscan_query;              
    procArr[0].updateFunc = check_update;

    procArr[0].runtime = 5000000;//2000ms
    procArr[0].queryInterval = 200000;//200ms
    procArr[0].queryTimes = 5;


    procArr[1].readParamFunc = transtube_gotosrc_read_param;              
    procArr[1].actFunc = lid_operation_act;
    procArr[1].queryFunc = openlid_gotoscan_query;              
    procArr[1].updateFunc = check_update;

    procArr[1].runtime = 20000000;//2000ms
    procArr[1].queryInterval = 200000;//200ms
    procArr[1].queryTimes = 5;


    procArr[2].readParamFunc = transtube_jawzdown1_read_param;              
    procArr[2].actFunc = lid_operation_act;
    procArr[2].queryFunc = openlid_gotoscan_query;              
    procArr[2].updateFunc = check_update;

    procArr[2].runtime = 5000000;//2000ms
    procArr[2].queryInterval = 200000;//200ms
    procArr[2].queryTimes = 5;

    procArr[3].readParamFunc = transtube_dp1jawclose_read_param;              
    procArr[3].actFunc = lid_operation_act;//dp1_jaw_act;
    procArr[3].queryFunc = openlid_gotoscan_query;              
    procArr[3].updateFunc = check_update;

    procArr[3].runtime = 5000000;//2000ms
    procArr[3].queryInterval = 200000;//200ms
    procArr[3].queryTimes = 5;

    procArr[4].readParamFunc = transtube_jawzup1_read_param;              
    procArr[4].actFunc = lid_operation_act;
    procArr[4].queryFunc = openlid_gotoscan_query;              
    procArr[4].updateFunc = check_update;

    procArr[4].runtime = 5000000;//2000ms
    procArr[4].queryInterval = 200000;//200ms
    procArr[4].queryTimes = 5;

    procArr[5].readParamFunc = transtube_gototar_read_param;              
    procArr[5].actFunc = lid_operation_act;
    procArr[5].queryFunc = openlid_gotoscan_query;              
    procArr[5].updateFunc = check_update;

    procArr[5].runtime = 20000000;//2000ms
    procArr[5].queryInterval = 200000;//200ms
    procArr[5].queryTimes = 5;

    procArr[6].readParamFunc = transtube_jawzdown2_read_param;              
    procArr[6].actFunc = lid_operation_act;
    procArr[6].queryFunc = openlid_gotoscan_query;              
    procArr[6].updateFunc = check_update;

    procArr[6].runtime = 5000000;//2000ms
    procArr[6].queryInterval = 200000;//200ms
    procArr[6].queryTimes = 5;

    procArr[7].readParamFunc = transtube_dp1jawopen_read_param;              
    procArr[7].actFunc = lid_operation_act;//dp1_jaw_act;
    procArr[7].queryFunc = openlid_gotoscan_query;              
    procArr[7].updateFunc = check_update;

    procArr[7].runtime = 5000000;//2000ms
    procArr[7].queryInterval = 200000;//200ms
    procArr[7].queryTimes = 5;
    
    procArr[8].readParamFunc = transtube_jawzup2_read_param;              
    procArr[8].actFunc = lid_operation_act;
    procArr[8].queryFunc = openlid_gotoscan_query;              
    procArr[8].updateFunc = check_update;

    procArr[8].runtime = 5000000;//2000ms
    procArr[8].queryInterval = 200000;//200ms
    procArr[8].queryTimes = 5;
    

    ptrProc->configProc(procArr,numProc);
    ptrProc->start(I_MODULE_DP1TRANSTUBE);

    pManagerIn->procListRunning.push_back(ptrProc);
}

void set_for_dp8lld(void * actParam)
{    
    pthread_t threadHandle;
    pthread_create(&threadHandle,NULL, dp8_lld_threadfunc,actParam);
}


void set_for_dp8capsample(void * actParam)
{    
    pthread_t threadHandle;
    pthread_create(&threadHandle,NULL, funcSampleCap,actParam);
}